home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
game
/
board
/
Crafty-15.19.lha
/
crafty-15.19
/
src
/
unmake.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-09-13
|
16KB
|
480 lines
#include <stdio.h>
#include <stdlib.h>
#include "chess.h"
#include "data.h"
/* last modified 03/11/98 */
/*
********************************************************************************
* *
* UnMakeMove() is responsible for updating the position database whenever a *
* move is retracted. it is the exact inverse of MakeMove(). *
* *
********************************************************************************
*/
void UnMakeMove(TREE *tree, int ply, int move, int wtm)
{
register int piece, from, to, captured, promote;
BITBOARD bit_move;
/*
----------------------------------------------------------
| |
| first, take care of the hash key if there's a possible |
| enpassant pawn capture. |
| |
----------------------------------------------------------
*/
HashKey=tree->save_hash_key[ply];
PawnHashKey=tree->save_pawn_hash_key[ply];
/*
----------------------------------------------------------
| |
| now do the piece-specific things by calling the |
| appropriate routine. |
| |
----------------------------------------------------------
*/
piece=Piece(move);
from=From(move);
to=To(move);
captured=Captured(move);
promote=Promote(move);
UnMakePieceMove:
SetRL90(from,OccupiedRL90);
SetRL45(from,OccupiedRL45);
SetRR45(from,OccupiedRR45);
ClearRL90(to,OccupiedRL90);
ClearRL45(to,OccupiedRL45);
ClearRR45(to,OccupiedRR45);
bit_move=Or(set_mask[from],set_mask[to]);
PieceOnSquare(to)=0;
switch (piece) {
/*
********************************************************************************
* *
* unmake pawn moves. *
* *
********************************************************************************
*/
case pawn:
if (wtm) {
ClearSet(bit_move,WhitePawns);
ClearSet(bit_move,WhitePieces);
PieceOnSquare(from)=pawn;
if (captured == 1) {
if(EnPassant(ply) == to) {
TotalPieces++;
SetRL90(to-8,OccupiedRL90);
SetRL45(to-8,OccupiedRL45);
SetRR45(to-8,OccupiedRR45);
Set(to-8,BlackPawns);
Set(to-8,BlackPieces);
PieceOnSquare(to-8)=-pawn;
Material-=PAWN_VALUE;
TotalBlackPawns++;
captured=0;
}
}
/*
--------------------------------------------------------------------
| |
| if this is a pawn promotion, remove the pawn from the counts |
| then update the correct piece board to reflect the piece just |
| created. |
| |
--------------------------------------------------------------------
*/
if (promote) {
TotalWhitePawns++;
Material+=PAWN_VALUE;
Clear(to,WhitePawns);
Clear(to,WhitePieces);
switch (promote) {
case knight:
Clear(to,WhiteKnights);
TotalWhitePieces-=knight_v;
WhiteMinors--;
Material-=KNIGHT_VALUE;
break;
case bishop:
Clear(to,WhiteBishops);
Clear(to,BishopsQueens);
TotalWhitePieces-=bishop_v;
WhiteMinors--;
Material-=BISHOP_VALUE;
break;
case rook:
Clear(to,WhiteRooks);
Clear(to,RooksQueens);
TotalWhitePieces-=rook_v;
WhiteMajors--;
Material-=ROOK_VALUE;
break;
case queen:
Clear(to,WhiteQueens);
Clear(to,BishopsQueens);
Clear(to,RooksQueens);
TotalWhitePieces-=queen_v;
WhiteMajors-=2;
Material-=QUEEN_VALUE;
break;
}
}
}
else {
ClearSet(bit_move,BlackPawns);
ClearSet(bit_move,BlackPieces);
PieceOnSquare(from)=-pawn;
if (captured == 1) {
if(EnPassant(ply) == to) {
TotalPieces++;
SetRL90(to+8,OccupiedRL90);
SetRL45(to+8,OccupiedRL45);
SetRR45(to+8,OccupiedRR45);
Set(to+8,WhitePawns);
Set(to+8,WhitePieces);
PieceOnSquare(to+8)=pawn;
Material+=PAWN_VALUE;
TotalWhitePawns++;
captured=0;
}
}
/*
--------------------------------------------------------------------
| |
| if this is a pawn promotion, remove the pawn from the counts |
| then update the correct piece board to reflect the piece just |
| created. |
| |
--------------------------------------------------------------------
*/
if (promote) {
TotalBlackPawns++;
Material-=PAWN_VALUE;
Clear(to,BlackPawns);
Clear(to,BlackPieces);
switch (promote) {
case knight:
Clear(to,BlackKnights);
TotalBlackPieces-=knight_v;
BlackMinors--;
Material+=KNIGHT_VALUE;
break;
case bishop:
Clear(to,BlackBishops);
Clear(to,BishopsQueens);
TotalBlackPieces-=bishop_v;
BlackMinors--;
Material+=BISHOP_VALUE;
break;
case rook:
Clear(to,BlackRooks);
Clear(to,RooksQueens);
TotalBlackPieces-=rook_v;
BlackMajors--;
Material+=ROOK_VALUE;
break;
case queen:
Clear(to,BlackQueens);
Clear(to,BishopsQueens);
Clear(to,RooksQueens);
TotalBlackPieces-=queen_v;
BlackMajors-=2;
Material+=QUEEN_VALUE;
break;
}
}
}
break;
/*
********************************************************************************
* *
* unmake knight moves. *
* *
********************************************************************************
*/
case knight:
if (wtm) {
ClearSet(bit_move,WhiteKnights);
ClearSet(bit_move,WhitePieces);
PieceOnSquare(from)=knight;
}
else {
ClearSet(bit_move,BlackKnights);
ClearSet(bit_move,BlackPieces);
PieceOnSquare(from)=-knight;
}
break;
/*
********************************************************************************
* *
* unmake bishop moves. *
* *
********************************************************************************
*/
case bishop:
ClearSet(bit_move,BishopsQueens);
if (wtm) {
ClearSet(bit_move,WhiteBishops);
ClearSet(bit_move,WhitePieces);
PieceOnSquare(from)=bishop;
}
else {
ClearSet(bit_move,BlackBishops);
ClearSet(bit_move,BlackPieces);
PieceOnSquare(from)=-bishop;
}
break;
/*
********************************************************************************
* *
* unmake rook moves. *
* *
**********************